﻿namespace ConsoleApp.DesignPatterns;


public class ConcreteSubject : ISubject  
{  
    private List<IObserver> _observers = new List<IObserver>();  
    private string _data;  
  
    public string Data  
    {  
        get { return _data; }  
        set  
        {  
            _data = value;  
            NotifyObservers();  
        }  
    }  
  
    public void RegisterObserver(IObserver observer)  
    {  
        _observers.Add(observer);  
    }  
  
    public void UnregisterObserver(IObserver observer)  
    {  
        _observers.Remove(observer);  
    }  
  
    public void NotifyObservers()  
    {  
        foreach (var observer in _observers)  
        {  
            observer.Update(_data);  
        }  
    }  
}